<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('头程装箱单-修改')" />
	<th:block th:include="include :: businessCSS" />
	<style>
        .main-content{position: relative;}
        .topbtns{position:fixed;top: 0;width: 100%;z-index: 9999;background-color: #fff;}
		.preservationBtn{padding: 10px;margin: 0;position: fixed;top: 0;z-index: 9999;background: #fff;width: 100%;}
		.preservationBtn input{font-size: 16px;background-color: rgb(80, 138, 238);color: #fff;border: none;padding: 5px 30px;border-radius: 5px;cursor: pointer;}
		.layui-table-tool-temp{padding-right: 30px;}
        .getDetailUpload,.getDetailUpload2{cursor: pointer;}
        .layui-table-tool-self{display: none;}
		.tablebody{background-color: #fff;padding: 20px;margin-right: 15px;}
		.tablebody input{display: inline;width: 80%;border: none;}
		.tablebody table{width: 100%;}
		.tablebody th,.tablebody td{border:solid 1px #ddd;padding:10px;font-size:14px;text-align: center;}
	</style>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	<form class="layui-form head-form">
<!--        <div class="topbtns"><th:block th:include="include :: business_btn" /></div>-->
	    <div class="north" style="background-color: #fff;margin-top: 55px;">
			 <div class="layui-form-item preservationBtn">
                <button class="layui-btn layui-btn-normal dhicon btn-edit" type="button" lay-submit lay-filter="btn-edit" id="btn-edit">保存</button>
<!--                <button class="layui-btn layui-btn-normal dhicon btn-sh" type="button" lay-submit lay-filter="btn-sh" id="btn-sh">审核</button>-->
<!--                <button class="layui-btn layui-btn-normal dhicon btn-retreat" type="button" lay-submit lay-filter="btn-retreat" id="btn-retreat">回退</button>-->
			</div>
<!--			<div style="width: 100%;height: 65px;background: #f6f6f6;"></div>-->
			<div class="forminput"></div>
    	</div>
        <div style="width: 100%;height: 10px;background: #f6f6f6;"></div>
        <div>
            <table class="layui-hide" id="mjdhtable" lay-filter="mjtable"></table>
            <script type="text/html" id="zjtoolbar">
                <div style="padding: 16px;display: flex;justify-content: space-between;">
                    <div  style="font-weight: 700;font-size: 18px;">海外头程装箱清单</div>
            		<div>
                        <button class="layui-btn layui-btn-normal dhicon updatebtn" classappend="'layui-btn-disabled'" lay-submit type="button"  lay-filter = "updatebtn" lay-event="updatebtn" id="updatebtn" th:if="${extraButton.updatebtn}">修改商品采购价</button>
<!--                        <button class="layui-btn layui-btn-danger dhicon" th:classappend="${enableEdit} == 1 ?'':'layui-btn-disabled'" type="button" th:disabled="${enableEdit} == 1 ?false:true" lay-event="mjbtn_save" id="btn-sh">删除</button>-->
            		</div>
            	</div>
            </script>
        </div>
        <th:block th:include="include :: pageFooter" />
    </form>
	</div>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: inlineJS" />


<script th:inline="javascript">
	/*<![CDATA[*/
	var fields = [[${fields}]];
    var fieldsList = [[${fieldsList}]];
	var fieldsHiddenList = [[${fieldsHiddenList}]];
	var moduleTable = [[${moduleTable}]];
	var enableEdit = [[${enableEdit}]];
    var List=[[${List}]];
	var listData1=List ?List:[]
	//品名免费数量
	var numFreeProName = [[${numFreeProName}]];
	//材质列表
	var textureList = [[${textureList}]];
	//材质最大值
	var texture = $('#priceQualityExtra').val();
	//表头数据
	var headData=[[${headData}]];
    var tablecols=[[ //标题栏
		{align: 'center', title: '商品信息', colspan: 16,width: 100}
		,{align: 'center', title: '装箱情况', colspan: 13,width: 100}
	], [
		{align: 'center',field: 'serial', title: '操作', width: 100}
		,{align: 'center',field: 'vDFilesDefault', title: '透明标附件', width: 100}
		,{align: 'center',field: 'isSign', title: '透明标记', width: 100}
        ,{align: 'center',field: 'commodityCode', title: '商品编码', width: 100}
        ,{align: 'center',field: 'name', title: '商品名称', width: 100}
		,{align: 'center',field: 'nameGoodsCn', title: '商品品名(中文)', width: 100}
		,{align: 'center',field: 'codeGoodsHs', title: '海关编码', width: 100}
		,{align: 'center',field: 'nameMaterialCn', title: '商品材质(中文)', width: 100}
        ,{align: 'center',field: 'priceIn', title: '商品采购价（¥）', width: 100}
        ,{align: 'center',field: 'linkJP', title: '竞品链接', width: 100}
        ,{align: 'center',field: 'vDFilesDefault', title: '是否有附件', width: 100,hide: true}
        ,{align: 'center',field: 'spGuid', title: '商品id', width: 100,hide: true}
		,{align: 'center',field: 'sku', title: 'SKU', width: 110}
		,{align: 'center',field: 'asin', title: 'ASIN', width: 110}
        ,{align: 'center',field: 'fnsku', title: 'FNSKU', width: 110}
        ,{align: 'center',field: 'numPlanDeliver', title: '计划发货数量', width: 100}
        ,{align: 'center',field: 'theFirstCase', title: '第一箱', width: 95,edit:'text'}
        ,{align: 'center',field: 'theSecondCase', title: '第二箱', width: 95,edit:'text'}
        ,{align: 'center',field: 'theThirdCase', title: '第三箱', width: 95,edit:'text'}
        ,{align: 'center',field: 'theFourCase', title: '第四箱', width: 95,edit:'text'}
        ,{align: 'center',field: 'theFiveCase', title: '第五箱', width: 95,edit:'text'}
        ,{align: 'center',field: 'theFixCase', title: '第六箱', width: 95,edit:'text'}
        ,{align: 'center',field: 'theSevenCase', title: '第七箱', width: 95,edit:'text'}
        ,{align: 'center',field: 'theEightCase', title: '第八箱', width: 95,edit:'text'}
        ,{align: 'center',field: 'theNineCase', title: '第九箱', width: 95,edit:'text'}
        ,{align: 'center',field: 'theTenCase', title: '第十箱', width: 95,edit:'text'}
    ]]


	var $,layer,form,table,nid,noTable;
    layui.use(['laydate','form','layer','jquery','util','element','upload','table'], function () {
        $ = layui.$,layer = layui.layer,form = layui.form,laydate = layui.laydate,util = layui.util,element=layui.element,upload = layui.upload,table = layui.table;
        beforeInit();//表单初始化之前的动作集合
		//初始化操作
		headcom3()
        nid=$('#nid').val()
         // 保存按钮事件变化
        $(function(){
           $('.tp-save').attr('onclick','')
           $('.tp-save').attr('lay-filter','btn-edit')
           $('.tp-save').attr('lay-submit',true)
        })

		//移除表格编辑属性  不等于制单中的时候禁用 已装箱和审核不能修改
		if (headData['state'] == 2 || headData['state'] == 1){
			$.each(tablecols[1],function(i,v){
						delete v['edit']
					}
			)
			// $('#numBox').attr('readonly','readonly').addClass('canntEdit');
		}

        
        // 保存操作
        form.on('submit(btn-edit)', function(data){
            var is_return = false//是否中断保存
            fieldsList.map((v,i)=>{
                if(v.fieldFrontRequired){
                    if(!$('#'+v.fields).val()){
                         layer.msg(v.fieldName+'不能为空')
                         is_return=true
                    }
                }
            })
			if ($('#numBox').val() <= 0){
				layer.msg("头程箱数不允许小于0");
				is_return=true;
			}
			if ($('#numBox').val() > 10){
				layer.msg("头程箱数不允许大于10");
				is_return=true;
			}
			listData1.map((n,m)=>{
				if(is_return){
					return;
				}
				if(n.sku != null) {
					var tolNum = Number(n.theFirstCase)+ Number(n.theSecondCase) + Number(n.theThirdCase) + Number(n.theFourCase)
							+ Number(n.theFiveCase) + Number(n.theFixCase) + Number(n.theSevenCase) + Number(n.theEightCase) + Number(n.theNineCase) + Number(n.theTenCase)
					if (tolNum <= 0){
						// 实际箱子数量不等于计划发货数量
						// layer.msg('SKU:'+n.sku+',实际箱子数量不等于计划发货数量');
						// 实际发货数量不能为0
						layer.msg('SKU:'+n.sku+',实际发货数量不能为0');
						is_return=true;
						return
					}
				} else {
					var numBox = $('#numBox').val();
					if (numBox>= 1){
						if (n.theFirstCase == ''){
							layer.msg(n.serial+'数据不全,请核实后再操作!');
							is_return=true;
							return
						}
					}
					if (numBox>= 2){
						if (n.theSecondCase == ''){
							layer.msg(n.serial+'数据不全,请核实后再操作!');
							is_return=true;
							return
						}
					}
					if (numBox>= 3){
						if (n.theThirdCase == ''){
							layer.msg(n.serial+'数据不全,请核实后再操作!');
							is_return=true;
							return
						}
					}
					if (numBox>= 4){
						if (n.theFourCase == ''){
							layer.msg(n.serial+'数据不全,请核实后再操作!');
							is_return=true;
							return
						}
					}
					if (numBox>= 5){
						if (n.theFiveCase == ''){
							layer.msg(n.serial+'数据不全,请核实后再操作!');
							is_return=true;
							return
						}
					}
					if (numBox>= 6){
						if (n.theFixCase == ''){
							layer.msg(n.serial+'数据不全,请核实后再操作!');
							is_return=true;
							return
						}
					}
					if (numBox>= 7){
						if (n.theSevenCase == ''){
							layer.msg(n.serial+'数据不全,请核实后再操作!');
							is_return=true;
							return
						}
					}
					if (numBox>= 8){
						if (n.theEightCase == ''){
							layer.msg(n.serial+'数据不全,请核实后再操作!');
							is_return=true;
							return
						}
					}
					if (numBox>= 9){
						if (n.theNineCase == ''){
							layer.msg(n.serial+'数据不全,请核实后再操作!');
							is_return=true;
							return
						}
					}
					if (numBox>= 10){
						if (n.theTenCase == ''){
							layer.msg(n.serial+'数据不全,请核实后再操作!');
							is_return=true;
							return
						}
					}
				}
			})
            if(is_return) return;
            $.modal.loading("正在处理中，请稍后...");
            listData1.map((v,i)=>{
                v.iid=i+1
            })
		    $.post("/logstics/fbabox/editpost",{infoMap:JSON.stringify(data.field),infoItems:JSON.stringify(listData1),sonData:JSON.stringify(listData1)},function(res){
                $.modal.closeLoading()
			 	layer.msg(res.msg);
				if(res.code==0){
					setTimeout(function(){
						window.location.href = '/logstics/fbabox/edit?guid=' + res.data;
					}, 1000);
				}
	        });
        });

		//按钮表格操作
		table.on('toolbar(mjtable)', function (obj) {
			switch (obj.event) {
				case 'updatebtn':
					var str = `<div class="tablebody"><table class="layui-table zjtable"><thead><tr><th>商品编码</th><th>商品名称</th><th>商品采购价(¥)</th><th>竞品链接</th></tr></thead><tbody id="tbody">`;
					$.each(listData1, function (i, v) {
						if (v.commodityCode != null){
							str += `<tr>`;
							str += `<td>${v.commodityCode}</td>`;
							str += `<td>${v.nameGoodsCn}</td>`;
							str += `<td><input style="text-align: center"  type="test" onkeyup="value=value.replace(/^\\D*(\\d*(?:\\.\\d{0,2})?).*$/g, '$1')" name='priceIn' class='priceIn'  id='priceIn' value=${v.priceIn}></td>`;
							str += `<td style="display: none">${v.serial}</td>`;
							str += `<td><input style="text-align: center;"  type="test"  name='linkJP' class='linkJP'  id='linkJP' value=${v.linkJP}></td>`;
							str += `</tr>`;
						}
					});
					str += `</tbody></table></div>`;
					layer.open({
						type: 1,
						area: [($(window).width() - 200)+'px', ($(window).height() - 100)+'px'],
						fix: false,//不固定
						offset: '10%',//距离顶部
						maxmin: true,//最大最小化
						shade: 0.3,//遮罩
						title: '修改商品采购价',
						content:str,
						btn: ['确定', '取消'],
						shadeClose: true,// 弹层外区域关闭
						yes: function(index, layero){
							showloadings(true);
							//获取修改后的清单信息
							var isjx=true
							var isLinP=true
							var trlist =$("#tbody").children("tr");
							var daraArr=[]
							//单箱采购总价
							var theFirstCasePrice = 0;
							var theSecondCasePrice = 0;
							var theThirdCasePrice = 0;
							var theFourCasePrice = 0;
							var theFiveCasePrice = 0;
							var theFixCasePrice = 0;
							var theSevenCasePrice = 0;
							var theEightCasePrice = 0;
							var theNineCasePrice = 0;
							var theTenCasePrice = 0;

							//装箱是否有箱子数量
							var theFirstCaseF = false;
							var theSecondCaseF = false;
							var theThirdCaseF = false;
							var theFourCaseF = false;
							var theFiveCaseF = false;
							var theFixCaseF = false;
							var theSevenCaseF = false;
							var theEightCaseF = false;
							var theNineCaseF = false;
							var theTenCaseF = false;
							for (var i = 0; i < trlist.length; i++) {
								let obj={}
								var tdarr = trlist.eq(i).find("td");
								obj.commodityCode = tdarr.eq(0).text();
								obj.nameGoodsCn = tdarr.eq(1).text();
								obj.priceIn = tdarr.eq(2).find("input").val();
								obj.priceIn = Number(obj.priceIn);
								obj.serial = tdarr.eq(3).text();
								obj.linkJP = tdarr.eq(4).find("input").val();
								if(obj.priceIn == null || obj.priceIn == '' || Number(obj.priceIn) == 0 || obj.priceIn == undefined)isjx=false
								if(obj.linkJP == null || obj.linkJP.trim() == '')isLinP=false
								daraArr.push(obj)
							}
							if(!isjx){
								showloadings(false) ;
								return layer.msg('请填写商品采购价') ;
							}
							if(!isLinP){
								showloadings(false) ;
								return layer.msg('请填写竞品链接') ;
							}

							//判断修改后的数据进行筛选在回填
							listData1.map((n,m)=>{
								if (!isNaN(n.serial)) {
									for (let j = 0; j < daraArr.length; j++) {
										if (n.serial == daraArr[j].serial){
											n.priceIn= daraArr[j].priceIn
											n.linkJP= daraArr[j].linkJP
										}
									}
									if (Number(n.theFirstCase) > 0){
										theFirstCaseF = true;
									}
									if (Number(n.theSecondCase) > 0){
										theSecondCaseF = true;
									}
									if (Number(n.theThirdCase) > 0){
										theThirdCaseF = true;
									}
									if (Number(n.theFourCase) > 0){
										theFourCaseF = true;
									}
									if (Number(n.theFiveCase) > 0){
										theFiveCaseF = true;
									}
									if (Number(n.theFixCase) > 0){
										theFixCaseF = true;
									}
									if (Number(n.theSevenCase) > 0){
										theSevenCaseF = true;
									}
									if (Number(n.theEightCase) > 0){
										theEightCaseF = true;
									}
									if (Number(n.theNineCase) > 0){
										theNineCaseF = true;
									}
									if (Number(n.theTenCase) > 0){
										theTenCaseF = true;
									}
									theFirstCasePrice =  theFirstCasePrice + (n.priceIn * Number(n.theFirstCase));
									theSecondCasePrice  =  theSecondCasePrice  + (n.priceIn * Number(n.theSecondCase));
									theThirdCasePrice   =  theThirdCasePrice   + (n.priceIn * Number(n.theThirdCase));
									theFourCasePrice    =  theFourCasePrice    + (n.priceIn * Number(n.theFourCase));
									theFiveCasePrice    =  theFiveCasePrice    + (n.priceIn * Number(n.theFiveCase));
									theFixCasePrice     =  theFixCasePrice     + (n.priceIn * Number(n.theFixCase));
									theSevenCasePrice   =  theSevenCasePrice   + (n.priceIn * Number(n.theSevenCase));
									theEightCasePrice   =  theEightCasePrice   + (n.priceIn * Number(n.theEightCase));
									theNineCasePrice    =  theNineCasePrice    + (n.priceIn * Number(n.theNineCase));
									theTenCasePrice    =  theTenCasePrice    + (n.priceIn * Number(n.theTenCase));
								}
								if (n.serial == "单箱采购总价(￥)") {
									n.theFirstCase = theFirstCaseF?theFirstCasePrice.toFixed(2):'';
									n.theSecondCase = theSecondCaseF?theSecondCasePrice.toFixed(2):'';
									n.theThirdCase = theThirdCaseF?theThirdCasePrice.toFixed(2):'';
									n.theFourCase = theFourCaseF?theFourCasePrice.toFixed(2):'';
									n.theFiveCase = theFiveCaseF?theFiveCasePrice.toFixed(2):'';
									n.theFixCase = theFixCaseF?theFixCasePrice.toFixed(2):'';
									n.theSevenCase = theSevenCaseF?theSevenCasePrice.toFixed(2):'';
									n.theEightCase = theEightCaseF?theEightCasePrice.toFixed(2):'';
									n.theNineCase = theNineCaseF?theNineCasePrice.toFixed(2):'';
									n.theTenCase = theTenCaseF?theTenCasePrice.toFixed(2):'';
								}
							});

							var realityPriceTOl = theFirstCasePrice + theSecondCasePrice + theThirdCasePrice + theFourCasePrice
									+ theFiveCasePrice + theFixCasePrice + theSevenCasePrice + theEightCasePrice
									+ theNineCasePrice + theTenCasePrice;
							//实际采购总价
							$('#realityPurchasePrice').val(realityPriceTOl.toFixed(2));
							layer.msg('修改成功') ;
							setTimeout(function () {
								layer.closeAll();
								sessionStorage.setItem(moduleTable + 'checkdata', '')
								showloadings(false);
								table.reload('mjdhtable', {data:listData1});
							}, 1000);
						}
					});
					break;
			};
		});


        
		// 初始化表格
        $.tablelist.init({
            elem: '#mjdhtable'
            ,data: listData1
            , page: false
            , even: true
            , limit: 10000
            , totalRow: false
            , cols: tablecols
            , toolbar: '#zjtoolbar'
            , defaultToolbar: [{title: '列设置', layEvent: 'fieldSet', icon: 'layui-icon-set'}]
            , height: '550'
            , done: function (res, curr, count) {
                listData1 = table.cache.mjdhtable;//每次重载都赋值更新表缓存
				if (headData['state'] == 1){
					$('.btn-sh').attr('disabled',true)
					$('.btn-sh').css('background',"#bbb")
					$('.btn-edit').attr('disabled',true)
					$('.btn-edit').css('background',"#bbb")
					$('.layui-col-xs4').attr("disabled",true);
					$('input').attr('disabled','disabled')
					$('input').addClass('canntEdit')
					$('.forminput').addClass('layui-disabled')
					$('.updatebtn').css('background',"#bbb")
					$('.updatebtn').attr('disabled',true)
				}
            },success:function(a,b,c){
                console.log(a,b,c)
            }
        });

        //监听单元格编辑
        table.on('edit(mjtable)', function(obj) {
			var weightReal;
			var numBox = 0;
			var theFirstCaseLength = 0;
			var theFirstCaseWidth = 0;
			var theFirstCaseHeight = 0;
			var theSecondCaseLength = 0;
			var theSecondCaseWidth = 0;
			var theSecondCaseHeight = 0;
			var theThirdCaseLength = 0;
			var theFourCaseLength = 0;
			var theFiveCaseLength = 0;
			var theFixCaseLength = 0;
			var theSevenCaseLength = 0;
			var theEightCaseLength = 0;
			var theNineCaseLength = 0;
			var theTenCaseLength = 0;
			var theThirdCaseWidth = 0;
			var theFourCaseWidth = 0;
			var theFiveCaseWidth = 0;
			var theFixCaseWidth = 0;
			var theSevenCaseWidth = 0;
			var theEightCaseWidth = 0;
			var theNineCaseWidth = 0;
			var theTenCaseWidth = 0;
			var theThirdCaseHeight = 0;
			var theFourCaseHeight = 0;
			var theFiveCaseHeight = 0;
			var theFixCaseHeight = 0;
			var theSevenCaseHeight = 0;
			var theEightCaseHeight = 0;
			var theNineCaseHeight = 0;
			var theTenCaseHeight = 0;
			//单箱采购总价
			var theFirstCasePrice = 0;
			var theSecondCasePrice = 0;
			var theThirdCasePrice = 0;
			var theFourCasePrice = 0;
			var theFiveCasePrice = 0;
			var theFixCasePrice = 0;
			var theSevenCasePrice = 0;
			var theEightCasePrice = 0;
			var theNineCasePrice = 0;
			var theTenCasePrice = 0;
			//装箱是否有箱子数量
			var theFirstCaseF = false;
			var theSecondCaseF = false;
			var theThirdCaseF = false;
			var theFourCaseF = false;
			var theFiveCaseF = false;
			var theFixCaseF = false;
			var theSevenCaseF = false;
			var theEightCaseF = false;
			var theNineCaseF = false;
			var theTenCaseF = false;
			var weightVol = 0;
			var tr = obj.tr;
			var regular = /^[+]{0,1}(\d+)$/  //正数 （不包括小数）
			var regular2 = /^[0-9]+(.[0-9]{0,2})?$/
			// 单元格编辑之前的值
			var oldtext = $(tr).find("td[data-field='"+obj.field+"'] div").text();
			//判断是否数值匹配
			listData1.map((n,m)=>{
				if(n.commodityCode == obj.data.commodityCode && n.commodityCode != null){
					if(n.sku != null){
						if (!regular.test(obj.value) && obj.value != '') {
							n[obj.field]  = oldtext;
							layer.msg("箱子数量只允许输入正整数,请核实后在操作!")
							return
						}
						if (obj.value == 0){
							//当0设置空值
							n[obj.field] = '';
						}
						var tolNum = Number(n.theFirstCase)+ Number(n.theSecondCase) + Number(n.theThirdCase) + Number(n.theFourCase)
								+ Number(n.theFiveCase) + Number(n.theFixCase) + Number(n.theSevenCase) + Number(n.theEightCase) + Number(n.theNineCase) + Number(n.theTenCase)
						if (n.numPlanDeliver < tolNum){
							//总的箱数不允许超过计划发货数量
							n[obj.field]  = oldtext;
							layer.msg('总的箱数不允许超过计划发货数量');
							return
						}
					}
				} else if(n.serial == obj.data.serial) {
					//箱规信息
					if (!regular2.test(obj.value) && obj.value != '') {
						n[obj.field]  = oldtext;
						layer.msg("箱规信息只允许输入两位小数点的正数,请核实后在操作!")
						return
					}
					if (obj.value == 0){
						//当0设置空值
						n[obj.field] = '';
					}
				}
			})
			listData1.map((n,m)=>{
				if (n.serial == "箱重(kg)") {
					weightReal = Number(n.theFirstCase) + Number(n.theSecondCase) + Number(n.theThirdCase) + Number(n.theFourCase)
							+ Number(n.theFiveCase) + Number(n.theFixCase) + Number(n.theSevenCase) + Number(n.theEightCase) + Number(n.theNineCase) + Number(n.theTenCase);
					//判断箱重有值箱数就有一箱
					if(Number(n.theFirstCase) != 0){
						numBox += 1;
					}
					if(Number(n.theSecondCase) != 0){
						numBox += 1;
					}
					if(Number(n.theThirdCase) != 0){
						numBox += 1;
					}
					if(Number(n.theFourCase) != 0){
						numBox += 1;
					}
					if(Number(n.theFiveCase) != 0){
						numBox += 1;
					}
					if(Number(n.theFixCase) != 0){
						numBox += 1;
					}
					if(Number(n.theSevenCase) != 0){
						numBox += 1;
					}
					if(Number(n.theEightCase) != 0){
						numBox += 1;
					}
					if(Number(n.theNineCase) != 0){
						numBox += 1;
					}
					if(Number(n.theTenCase) != 0){
						numBox += 1;
					}

				}
				if (n.serial == "箱规长(cm)") {
					theFirstCaseLength = Number(n.theFirstCase);
					theSecondCaseLength = Number(n.theSecondCase);
					theThirdCaseLength = Number(n.theThirdCase);
					theFourCaseLength = Number(n.theFourCase);
					theFiveCaseLength = Number(n.theFiveCase);
					theFixCaseLength = Number(n.theFixCase);
					theSevenCaseLength = Number(n.theSevenCase);
					theEightCaseLength = Number(n.theEightCase);
					theNineCaseLength = Number(n.theNineCase);
					theTenCaseLength = Number(n.theTenCase);
				}
				if (n.serial == "箱规宽(cm)") {
					theFirstCaseWidth = Number(n.theFirstCase);
					theSecondCaseWidth = Number(n.theSecondCase);
					theThirdCaseWidth = Number(n.theThirdCase);
					theFourCaseWidth = Number(n.theFourCase);
					theFiveCaseWidth = Number(n.theFiveCase);
					theFixCaseWidth = Number(n.theFixCase);
					theSevenCaseWidth = Number(n.theSevenCase);
					theEightCaseWidth = Number(n.theEightCase);
					theNineCaseWidth = Number(n.theNineCase);
					theTenCaseWidth = Number(n.theTenCase);
				}
				if (n.serial == "箱规高(cm)") {
					theFirstCaseHeight = Number(n.theFirstCase);
					theSecondCaseHeight = Number(n.theSecondCase);
					theThirdCaseHeight = Number(n.theThirdCase);
					theFourCaseHeight = Number(n.theFourCase);
					theFiveCaseHeight = Number(n.theFiveCase);
					theFixCaseHeight = Number(n.theFixCase);
					theSevenCaseHeight = Number(n.theSevenCase);
					theEightCaseHeight = Number(n.theEightCase);
					theNineCaseHeight = Number(n.theNineCase);
					theTenCaseHeight = Number(n.theTenCase);
				}
				if (n.serial == "抛重(kg)") {
					n.theFirstCase = ((theFirstCaseLength * theFirstCaseWidth * theFirstCaseHeight)/headData.coefficientWeight).toFixed(2)
					n.theSecondCase = ((theSecondCaseLength * theSecondCaseWidth * theSecondCaseHeight)/headData.coefficientWeight).toFixed(2)
					n.theThirdCase = ((theThirdCaseLength * theThirdCaseWidth * theThirdCaseHeight)/headData.coefficientWeight).toFixed(2)
					n.theFourCase = ((theFourCaseLength * theFourCaseWidth * theFourCaseHeight)/headData.coefficientWeight).toFixed(2)
					n.theFiveCase = ((theFiveCaseLength * theFiveCaseWidth * theFiveCaseHeight)/headData.coefficientWeight).toFixed(2)
					n.theFixCase = ((theFixCaseLength * theFixCaseWidth * theFixCaseHeight)/headData.coefficientWeight).toFixed(2)
					n.theSevenCase = ((theSevenCaseLength * theSevenCaseWidth * theSevenCaseHeight)/headData.coefficientWeight).toFixed(2)
					n.theEightCase = ((theEightCaseLength * theEightCaseWidth * theEightCaseHeight)/headData.coefficientWeight).toFixed(2)
					n.theNineCase = ((theNineCaseLength * theNineCaseWidth * theNineCaseHeight)/headData.coefficientWeight).toFixed(2)
					n.theTenCase = ((theTenCaseLength * theTenCaseWidth * theTenCaseHeight)/headData.coefficientWeight).toFixed(2)

					if(theFirstCaseLength == 0 && theFirstCaseWidth == 0 && theFirstCaseHeight == 0){
						n.theFirstCase = '';
					}

					if(theSecondCaseLength == 0 && theSecondCaseWidth == 0 && theSecondCaseHeight == 0){
						n.theSecondCase = '';
					}

					if(theThirdCaseLength == 0 && theThirdCaseWidth == 0 && theThirdCaseHeight == 0){
						n.theThirdCase = '';
					}

					if(theFourCaseLength == 0 && theFourCaseWidth == 0 && theFourCaseHeight == 0){
						n.theFourCase = '';
					}

					if(theFiveCaseLength == 0 && theFiveCaseWidth == 0 && theFiveCaseHeight == 0){
						n.theFiveCase = '';
					}

					if(theFixCaseLength == 0 && theFixCaseWidth == 0 && theFixCaseHeight == 0){
						n.theFixCase = '';
					}

					if(theSevenCaseLength == 0 && theSevenCaseWidth == 0 && theSevenCaseHeight == 0){
						n.theSevenCase = '';
					}

					if(theEightCaseLength == 0 && theEightCaseWidth == 0 && theEightCaseHeight == 0){
						n.theEightCase = '';
					}

					if(theNineCaseLength == 0 && theNineCaseWidth == 0 && theNineCaseHeight == 0){
						n.theNineCase = '';
					}

					if(theTenCaseLength == 0 && theTenCaseWidth == 0 && theTenCaseHeight == 0){
						n.theTenCase = '';
					}

					weightVol = Number(n.theFirstCase) + Number(n.theSecondCase) + Number(n.theThirdCase) + Number(n.theFourCase) + Number(n.theFiveCase)
						+ Number(n.theFixCase) + Number(n.theSevenCase) + Number(n.theEightCase) + Number(n.theNineCase) + Number(n.theTenCase);
				}
				if (!isNaN(n.serial)) {
					if (Number(n.theFirstCase) > 0){
						theFirstCaseF = true;
					}
					if (Number(n.theSecondCase) > 0){
						theSecondCaseF = true;
					}
					if (Number(n.theThirdCase) > 0){
						theThirdCaseF = true;
					}
					if (Number(n.theFourCase) > 0){
						theFourCaseF = true;
					}
					if (Number(n.theFiveCase) > 0){
						theFiveCaseF = true;
					}
					if (Number(n.theFixCase) > 0){
						theFixCaseF = true;
					}
					if (Number(n.theSevenCase) > 0){
						theSevenCaseF = true;
					}
					if (Number(n.theEightCase) > 0){
						theEightCaseF = true;
					}
					if (Number(n.theNineCase) > 0){
						theNineCaseF = true;
					}
					if (Number(n.theTenCase) > 0){
						theTenCaseF = true;
					}
					theFirstCasePrice =  theFirstCasePrice + (n.priceIn * Number(n.theFirstCase));
					theSecondCasePrice  =  theSecondCasePrice  + (n.priceIn * Number(n.theSecondCase));
					theThirdCasePrice   =  theThirdCasePrice   + (n.priceIn * Number(n.theThirdCase));
					theFourCasePrice    =  theFourCasePrice    + (n.priceIn * Number(n.theFourCase));
					theFiveCasePrice    =  theFiveCasePrice    + (n.priceIn * Number(n.theFiveCase));
					theFixCasePrice     =  theFixCasePrice     + (n.priceIn * Number(n.theFixCase));
					theSevenCasePrice   =  theSevenCasePrice   + (n.priceIn * Number(n.theSevenCase));
					theEightCasePrice   =  theEightCasePrice   + (n.priceIn * Number(n.theEightCase));
					theNineCasePrice    =  theNineCasePrice    + (n.priceIn * Number(n.theNineCase));
					theTenCasePrice    =  theTenCasePrice    + (n.priceIn * Number(n.theTenCase));
				}
				if (n.serial == "单箱采购总价(￥)") {
					n.theFirstCase = theFirstCaseF?theFirstCasePrice.toFixed(2):'';
					n.theSecondCase = theSecondCaseF?theSecondCasePrice.toFixed(2):'';
					n.theThirdCase = theThirdCaseF?theThirdCasePrice.toFixed(2):'';
					n.theFourCase = theFourCaseF?theFourCasePrice.toFixed(2):'';
					n.theFiveCase = theFiveCaseF?theFiveCasePrice.toFixed(2):'';
					n.theFixCase = theFixCaseF?theFixCasePrice.toFixed(2):'';
					n.theSevenCase = theSevenCaseF?theSevenCasePrice.toFixed(2):'';
					n.theEightCase = theEightCaseF?theEightCasePrice.toFixed(2):'';
					n.theNineCase = theNineCaseF?theNineCasePrice.toFixed(2):'';
					n.theTenCase = theTenCaseF?theTenCasePrice.toFixed(2):'';
				}
			})
			var realityPriceTOl = theFirstCasePrice + theSecondCasePrice + theThirdCasePrice + theFourCasePrice
								+ theFiveCasePrice + theFixCasePrice + theSevenCasePrice + theEightCasePrice
			 					+ theNineCasePrice + theTenCasePrice;
			//实际采购总价
			$('#realityPurchasePrice').val(realityPriceTOl.toFixed(2));
			$('#weightReal').val(weightReal.toFixed(2));
			$('#weightVol').val(weightVol.toFixed(2));
			//装箱计重=MAX(实重/抛重)
			var weightCal = weightReal>weightVol?weightReal:weightVol;
			$('#weightCal').val(precision(weightCal));
			// if (weightReal >= $('#weightVol').val()){
			// 	$('#weightCal').val(weightReal.toFixed(2));
			// } else {
			// 	$('#weightCal').val($('#weightVol').val());
			// }
			$('#numBox').val(numBox);
			update(listData1,$('#numProName').val(),textureList);
			table.reload('mjdhtable', {data:listData1});

		})

    });

	//根据数字未满5满5,未满10满10
	function precision(f) {
		var s = f.toString();
		var rs = s.indexOf('.');
		if (rs != -1) {
			//取出第一位
			var first = s.substring(0,rs);
			//根据第一位小数5来判断，大于0.5以上进1,小于0.5的为0.5
			first = first + '.5';
			if (f < first){
				f = first
			} else if(f > first) {
				f =Math.round(f);
			}
		}
		return f
	}

	/**
	 * 回调弹框事件
	 */
	function getMoreAfter(fieldsList,fields,tindex,fieldName,fieldSearchType,isSearch,isLayer,res) {//弹出框赋值回调
		if(fields=='nameLogsticsPattern'){
			//免费数量
			numFreeProName = res.numFreeProName;
			//抛货系数
			$('#coefficientWeight').val(res.coefficientWeight);
			//根据物流code获取材质信息
			$.get('/business/logsticspatternDetails/list',{code:res.code},function(ress){
				if(ress.data.length>0){
					textureList = ress.data;
				}else{
					textureList = [];
				}
				update(listData1,$('#numProName').val(),textureList);
			})
		}

	}

	//物流名称修改调用一系列操作
	function  update(listData1,gradeNum,textureList) {
		texture = 0;
		listData1.map((n,m)=>{
			//判断是否是混合材质
			if (n.nameMaterialCn != null && typeof n.nameMaterialCn != "undefined") {
				if (n.nameMaterialCn.indexOf(",") == -1) {
					//赋值材质附加费(取最大值)
					for (let j = 0; j < textureList.length; j++) {
						if (textureList[j].materialName == n.nameMaterialCn) {
							if (textureList[j].materialCost > texture) {
								texture = textureList[j].materialCost;
							}
						}
					}
				} else {
					var nameMaterialCnList = n.nameMaterialCn.split(",");
					nameMaterialCnList.forEach(item => {
						for (let j = 0; j < textureList.length; j++) {
							if (textureList[j].materialName == item) {
								if (textureList[j].materialCost > texture) {
									texture = textureList[j].materialCost
								}
							}
						}
					});
				}
			}
		})

		//实际计重运费=装箱计重*重量计费标准
		$('#priceTranCalWeightPredict').val(($('#weightCal').val() * $('#priceCalPerKg').val()).toFixed(2));
		//设置表头附加费材质
		$('#priceQualityExtra').val(texture);
		//设置实际材质附加费=材质计费*重量
		$('#priceQualityExtraPredict').val(($('#priceQualityExtra').val()*$('#weightCal').val()).toFixed(2));
		//超出品名=实际品名-免费品名数
		var num = $('#numProName').val()-numFreeProName;
		$('#numProNameBeyond').val(num>0?num:0);
		//实际品名附加费 = 超出的品名*品名标准
		$('#priceProNameExtraPredict').val(($('#priceProNamePerOne').val() * $('#numProNameBeyond').val()).toFixed(2));
		//实际物流费用 = 实际计重运费+实际材质附加费+实际品名附加费
		$('#priceTranPredict').val(parseFloat($('#priceTranCalWeightPredict').val())+parseFloat($('#priceQualityExtraPredict').val())+parseFloat($('#priceProNameExtraPredict').val()));
	}

</script>

</body>
</html>